<template>
  <div class="trans-record-content">
    <van-empty description="暂无数据" v-if="showEmpty" />
    <!-- <van-pull-refresh v-model="refreshing"> -->
		<div class="content">
			<div class="account_cards_wrap">
				<scriptLink></scriptLink>
				<ul class="card_list">
					<li
						v-for="(item,index) in list"
						:key="index"
						@click="chooseCard(item)"
					>
						<div class="cards_item">
							<div class="card_info">
								<div class="item_icon">
									<svg class="icon bank_icon" aria-hidden="true">
										<use :xlink:href="'#'+item.bank_logo" />
									</svg>
								</div>
								<div class="item_info">
									<p>{{item.bank_name}}</p>
								</div>
							</div>
						</div>
					</li>
				</ul>
			</div>
		</div>
		
    <!-- </van-pull-refresh> -->
  </div>
</template>

<script>
import { List, Cell, Image, Toast, Empty, PullRefresh } from "vant";
import { getMessageBox } from "@/assets/js/utils";
import { getAllBank } from "@/api/api";
import bankCardList from "@/assets/js/bankCardList";
export default {
  name: "transRecord",
  components: {
		scriptLink: {
			render(createElement) {
				return createElement("script", {
					attrs: {
						type: "text/javascript",
						src: "//at.alicdn.com/t/font_1409441_hxsfeysl9j.js",
					},
				});
			},
		},
    vanList: List,
    vanCell: Cell,
    VanImage: Image,
    vanEmpty: Empty,
    vanPullRefresh: PullRefresh,
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
      pageNumber: 1,
      pageSize: 10,
      showEmpty: false,
      defaultIcon: require("../../../assets/images/default_user.png"),
      dataOption: {
        record_states: [
          {
            name: "转让中",
            value: 1,
            className: "type1",
          },
          {
            name: "转让成功",
            value: 2,
            className: "type2",
          },
          {
            name: "转让失败",
            value: 3,
            className: "type3",
          },
        ],
      },
    };
  },
	mounted(){
		this.onLoad()
	},
  methods: {
    onLoad() {
      getAllBank()
        .then((res) => {
          this.loading = false;
          if (res.code == 200000) {
						let arr = []
						for (let name in res.data) {
							arr.push({bank_name: res.data[name]})
						}
						console.log(arr)
						bankCardList.map((bankElem, bankIndex) => {
							arr.forEach((cardElem, index) => {
								if (
									bankElem.value == cardElem.bank_name ||
									bankElem.value == `中国${cardElem.bank_name}`
								) {
									cardElem.bank_logo = "icon" + bankIndex;
									return false;
								}
							});
						});
						this.list = arr
          } else if (res.code == 300016) {
            this.showEmpty = true;
            this.list = [];
            this.finished = true;
          } else {
            this.finished = true;
          }
        })
        .catch((err) => {
          this.loading = false;
          this.finished = true;
        });
    },
		// 选择银行卡
		chooseCard(item) {
			this.$router.push({
				path: "/beanTrans",
// 				query: {
// 					record_id: item.record_id,
// 				},
			});
			// this.setCheckedBack(item.id, item.bank_name);
		},
    onRefresh() {
      // 清空列表数据
      this.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
    // 详情
    toDetail(item) {
      this.$router.push({
        path: "/transRecordDetail",
        query: {
          record_id: item.record_id,
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.trans-record-content {
  .account_cards_wrap {
    overflow: hidden;
    border-bottom: 1px solid rgb(241, 241, 241);
    box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.11);
  
    ul.card_list {
      margin: 10px 15px 0;
      overflow: hidden;
  
      li {
        .cards_item {
          width: 100%;
          height: 84px;
          background-size: 100% 100%;
          border-radius: 10px 10px 0 0;
          overflow: hidden;
  
          .card_info {
            height: 50px;
            overflow: hidden;
            margin-top: 17px;
  
            .item_icon {
              width: 39px;
              height: 39px;
              background: #fff;
              border-radius: 50%;
              overflow: hidden;
              float: left;
              // margin-top: 5px;
              // margin-left: 20px;
  
              .bank_icon {
                padding: 0;
                width: 24px;
                height: 24px;
                display: block;
                margin: 8px auto;
                overflow: hidden;
              }
            }
  
            .item_info {
              float: left;
              width: 250px;
              margin-left: 20px;
  
              p,
              span {
                // color: #fff;
              }
  
              p:nth-of-type(1) {
                font-size: 18px;
                line-height: 39px;
              }
  
              p:nth-of-type(2) {
                line-height: 33px;
  
                span {
                  font-size: 14px;
                  line-height: 15px;
                }
              }
            }
          }
        }
  
        .cards_item.bank_bg_0 {
          background-image: url("../../../assets/images/bgcard0.png");
        }
  
        .cards_item.bank_bg_1 {
          background-image: url("../../../assets/images/bgcard1.png");
        }
  
        .cards_item.bank_bg_2 {
          background-image: url("../../../assets/images/bgcard2.png");
        }
      }
  
      li:not(:first-child) {
        margin-top: -8px;
      }
    }
  
    .key_board_wrap {
      padding-top: 20px;
  
      .van-number-keyboard {
        position: relative;
        margin-top: 20px;
      }
    }
  }
  
}
</style>
